<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
	<th:block th:include="include :: header('商品库')" />
	<th:block th:include="include :: list-css" />
	<style type="text/css">
		label.layui-form-label {width: 95px;padding-right: 0px;}
		.layui-form-radio {margin-top:0}
		.importTable{empty-cells:show;border-collapse:collapse;border-spacing:0;}
		.listext th{background:#eee;color:#3366cc;}
		.listext th,.listext td{border:solid 1px #ddd;text-align:left;padding:10px;font-size:14px;}
		
		#importProgress {z-index:20200202;background-color: #000;opacity: 0.3;display:none;}
		.importProgress {width:300px;z-index:20202222;position: fixed;top: 34%;left: 40%;display:none;}
		tr img{width: 30px !important;height: 30px !important;margin: 0 2px;}
		.ishide{display: none;}
        .bagimg{z-index: 999;max-width:200px;border: 5px solid #23b971}

		#importProgress {z-index:20200202;background-color: #000;opacity: 0.3;display:none;}
		.importProgress {width:300px;z-index:20202222;position: fixed;top: 34%;left: 40%;display:none;}

		.layui-tab-title{border-color: #ccc !important;}
        .layui-this{color: rgb(0, 135, 250) !important;background: none !important;}
        .layui-tab-brief > .layui-tab-title .layui-this:after, .layui-tab-brief > .layui-tab-more li.layui-this:after{border-color:  rgb(0, 135, 250) !important;}
        .mid-content {overflow: auto;}
		.ishide2{display: none;}
	</style>
</head>
<body>
<div class="ishide"><img class="bagimg" src=""/></div>
<div class="main-content">
	<div class="content-right">
		<div class="search-top">
			<span>查询条件</span>
			<a href="javascript:;" layadmin-event="flexible" class="menuBtn">
				<i class="layui-icon layui-icon-spread-left" id="LAY_app_flexible" style="color: #fff;"></i>
			</a>
		</div>
		<div class="panel layout-expand layui-expand-east">
		    <div class="panel-header">
		        <div class="panel-tool" style="text-align: center; width: 26px;height: 30px;line-height: 30px;">
		            <a href="javascript:;" layadmin-event="flexible" class="menuBtn">
		                <i class="layui-icon layui-icon-shrink-right" id="LAY_app_flexible" style="color: #fff;"></i>
		            </a>
		        </div>
		    </div>
		    <div class="panel-body panel-title" style="text-align: center; width: 26px;">查<br>询<br>条<br>件</div>
		</div>
       	<form class="layui-form">
			<th:block th:include="listinclude :: searchRight('page')" />
		</form>
   	</div>
    <div class="mid-content">
		<div class="layui-tab layui-tab-brief" lay-filter="demozf" style="margin-top: 0;">
			<ul class="layui-tab-title" >
				<li class="layui-this">商品列表</li>
				<li>子件列表</li>
			</ul>
			<div class="layui-tab-content"></div>
		</div>
		<table class="layui-hide" id="dhtable" lay-filter="ftable"></table>
	</div>
</div>
<!-- 表格头部工作栏-->
<script type="text/html" id="toolbar">
	<div class="layui-btn-container ishide1">
		<div class="layui-btn layui-table-tools importbtn-bg" lay-event="addbtn" shiro:hasPermission="business:productbasis:add">
			<i class="dhicon dh-plus"></i> 新增
        </div>
		<div class="layui-btn layui-btn-danger layui-table-tools" onclick="remove()" shiro:hasPermission="business:productbasis:delete">
            <p class="dhicon dh-remove" style="color:white;font-size:14px"><span class="fa_span">批量删除</span></p>
        </div>

		<div class="layui-btn layui-table-tools importbtn-bg" lay-event="importBtn" shiro:hasPermission="business:productbasis:import">
			<i class="dhicon dh-upload"></i> 导入
		</div>

		<div class="layui-btn layui-table-tools importbtn-bg" lay-event="exportbtn" shiro:hasPermission="business:productbasis:export">
			<i class="dhicon dh-download"></i> 导出
        </div>
    </div>
	<div class="layui-btn-container ishide2">
		<div class="layui-btn layui-btn-danger layui-table-tools" onclick="zjremove()" shiro:hasPermission="business:productbasis:delete">
            <p class="dhicon dh-remove" style="color:white;font-size:14px"><span class="fa_span">批量删除</span></p>
        </div>

		<div class="layui-btn layui-table-tools importbtn-bg" lay-event="zjimportBtn" shiro:hasPermission="business:productbasis:import">
			<i class="dhicon dh-upload"></i> 导入
		</div>

		<div class="layui-btn layui-table-tools importbtn-bg" lay-event="zjexportbtn" shiro:hasPermission="business:productbasis:export">
			<i class="dhicon dh-download"></i> 导出
        </div>
    </div>
</script>
<!-- 表格操作区 -->
<script type="text/html" id="barDh">
    <a class="layui-btn layui-btn-danger layui-btn-xs dhicon dh-remove" onclick="remove('{{d.guid}}','{{d.code}}')" shiro:hasPermission="business:productbasis:delete">&nbsp;删除</a>  
    <a class="layui-btn layui-btn-danger layui-btn-xs dhicon dh-edit"  onclick="updateState('{{d.guid}}', '{{ d.isUsable}}'=='停止' ?0 :1)" shiro:hasPermission="business:productbasis:edit">&nbsp;{{d.isUsable=='停止' ?'启用' :'停止'}}</a>
</script>
<script type="text/html"  id="file2_img">
	{{# if(d.img){ }}
	   <img src="{{d.img}}"/>
	{{# }else{ }}
	{{# } }}
</script>

<script type="text/template" id="importTpl">
	<form enctype="multipart/form-data" class="mt20 mb10">
		<div class="col-xs-offset-1">
			<input type="file" id="file" name="file"/>
			<div class="mt10 pt5">
				 <a onclick="$.tablelist.importTemplate('/business/productbasis/exporttemplate')" class="btn btn-default btn-xs"><i class="dhicon dh-file-excel-o"></i> 下载模板</a>
			</div>
			<font color="red" class="pull-left mt10">提示：仅允许导入“xls”或“xlsx”格式文件！</font>
		</div>
	</form>
</script>
<script type="text/template" id="zjimportTpl">
	<form enctype="multipart/form-data" class="mt20 mb10">
		<div class="col-xs-offset-1">
			<input type="file" id="file" name="file"/>
			<div class="mt10 pt5">
				 <a onclick="$.tablelist.importTemplate('/business/productbasis/exporttemplateZJ')" class="btn btn-default btn-xs"><i class="dhicon dh-file-excel-o"></i> 下载模板</a>
			</div>
			<font color="red" class="pull-left mt10">提示：仅允许导入“xls”或“xlsx”格式文件！</font>
		</div>
	</form>
</script>
<!-- 导入明细 -->
<div id="iTable" class="display_no">
	<table class="importTable listext" data-resizable-columns-id="demo-table">
	    <tbody id="itbody"></tbody>
	</table>
</div>

<!-- 导入进度条 -->
<div id="importProgress" class="layui-layer-shade">
</div>
<div class="importProgress">
	<div class="layui-progress layui-progress-big" lay-showpercent="true" lay-filter="dhprogress">
	  <div class="layui-progress-bar layui-bg-blue" lay-percent="0%"></div>
	</div>
</div>
<th:block th:include="include :: footer" />
<th:block th:include="include :: businessJS" />
<th:block th:include="include :: searchJS" />
<th:block th:include="listinclude :: list-templeat" />
<script th:src="@{/dhecp/js/queryCondition.js}"></script>


<script th:inline="javascript">
	/*<![CDATA[*/
	var prefix = ctx + "business/productbasis";
	var gridColumns = [[${gridColumns}]], 
		importFields =[[${importFields}]],
		importFieldsZJ =[[${importFieldsZJ}]],
		moduleTable =[[${moduleTable}]];
	/*]]>*/
</script>
<script type="text/javascript">
	var vCpFl = $(".layui-tab-title .layui-this").attr("typeid");
var element,thStr;
var fieldWidth = {},		//导入列表字段宽度
	filedRequired = {},		//导入列表必填字段
	dateFiled = [],			//导入列表日期字段
	hasNull = false;		//导入数据必填字段有空值
$.each(gridColumns.dictionaryForPageFieldList,function(i,v){
	fieldWidth[v.fields] = v.fieldFrontWidth
	if(v.fieldFrontRequired)filedRequired[v.fields] = v.fieldName;
	if(v.fieldFrontType == 't_date')dateFiled.push(v.fields);
})
var $,layer,laydate,form,table,wherestr={};
layui.use(['table','laydate','form','layer','jquery','element'], function () {
	$ = layui.$, layer = layui.layer,laydate = layui.laydate , form = layui.form, table = layui.table, element = layui.element;
	serachRender();//查询条件初始渲染集合
	changeDropdown('fSl');//导入窗口——税率下拉可编辑赋事件
	$.tablelist.init({
		elem: '#dhtable'
		,modalName: "产品信息"
		,url: prefix + '/list'
		,updateUrl: prefix + "/edit?guid={id}"
		,initSort: {field: 'createTime',type: 'asc'}
		,totalRow: gridColumns.totalRow
		,cols: [gridColumns.gridBody]
		,toolbar: '#toolbar'
		,defaultToolbar: [{title:'列设置',layEvent: 'fieldSet',icon: 'layui-icon-set'}] //这里在右边显示
		,height:'full-50',
		done:function(){
			firstimg()
		}
	});


	// 头部组装切换
	element.on('tab(demozf)', function(elem,a){
        var name=$(elem.elem.context).text()
        if(name==='商品列表'){
            tableUrl1 = prefix + "/list",
            vtype=1
        }else if(name==='子件列表'){
            tableUrl1 = prefix+"/listson",
            vtype=2
        }
        $.get(prefix+"/switchover",{num:vtype},function(data){
            // 初始化表格
            $.tablelist.init({
                elem: '#dhtable'
                ,url: tableUrl1
                , totalRow: data.totalRow
                , cols: [data.gridBody]
                , toolbar: '#toolbar'
                , defaultToolbar: [{title: '列设置', layEvent: 'fieldSet', icon: 'layui-icon-set'}]
                ,height:'full-80'
                , done: function (res, curr, count) {
                    listData1 = table.cache.dhtable;//每次重载都赋值更新表缓存
                    if(vtype === 1){
                        $('.ishide1').show()
                        $('.ishide2').hide()
                    }else if(vtype === 2){
                        $('.ishide1').hide()
                        $('.ishide2').show()
                    }
                },success:function(a,b,c){
                }
            });
          
            var cephalosome = document.getElementById("cephalosome");//获取所有的table
			var str = queryCondition(data.fixtype);
			cephalosome.innerHTML = str;
			form.render();
            serachRender()
			setTimeout(() => {firstimg()}, 1000);
        });
    });




	//监听排序事件 
	table.on('sort(ftable)', function(obj){
		$.tablelist.sort('dhtable',obj);
	});

	//监听行双击事件
    table.on('rowDouble(ftable)', function (obj) {
		// window.location.href = "/business/productbasis/edit?guid="+obj.data.guid;
		top.layui.index.openTabsPage(prefix+ "/edit?guid="+obj.data.guid,'商品库 - 修改')

    });

	//头工具栏事件
 	table.on('toolbar(ftable)', function(obj){
 	    switch(obj.event){
			case 'addbtn':
				top.layui.index.openTabsPage(prefix+ "/add",'商品库 - 新增')
				break;
	   		case 'exportbtn':
		   		$.ajax({
		   		    url: '/business/productbasis/export',
		   		    type: 'GET',
		   		    data: getWherestr(),
		   		    dataType: 'json',
		   		    beforeSend: function(){
			   			showloadings(true);
		   		    },
		   		    success: function(result){
		   		    	if (result.code == 0) {
					        window.location.href = ctx + "common/download?fileName=" + encodeURIComponent(result.msg) + "&delete=" + true;
					        parent.$('.page-loading').hide();//页面进行了跳转刷新，需要手动关闭页面的加载动画
						} else if (result.code == web_status.WARNING) {
		                   $.modal.alertWarning(result.msg)
		            	} else {
							$.modal.alertError(result.msg);
						}
				   		showloadings(false);
		   		    }
		   		});
	   		break;
			case 'zjexportbtn'://子件导出
		   		$.ajax({
		   		    url: '/business/productbasis/exportzj',
		   		    type: 'GET',
		   		    data: getWherestr(),
		   		    dataType: 'json',
		   		    beforeSend: function(){
			   			showloadings(true);
		   		    },
		   		    success: function(result){
		   		    	if (result.code == 0) {
					        window.location.href = ctx + "common/download?fileName=" + encodeURIComponent(result.msg) + "&delete=" + true;
					        parent.$('.page-loading').hide();//页面进行了跳转刷新，需要手动关闭页面的加载动画
						} else if (result.code == web_status.WARNING) {
		                   $.modal.alertWarning(result.msg)
		            	} else {
							$.modal.alertError(result.msg);
						}
				   		showloadings(false);
		   		    }
		   		});
	   		break;
			case 'importBtn'://导入
			    if (importFields) {
                    thStr = '<tr><th><div style="width:30px;">序号</div></th>';
                    $.each(importFields, function (i, val) {
                        fieldWidth[val] = fieldWidth[val] ? fieldWidth[val] : 100;	//默认宽度100px
                        thStr += '<th><div style="width:' + fieldWidth[val] + 'px;">' + i + '</div></th>';
                    })
                    thStr += '</tr>';
                    layer.open({
                        type: 1,
                        area: ['400px', '230px'],
                        fix: false, 
                        offset: '10%',
                        maxmin: true,
                        shade: 0.3,
                        title: '导入',
                        content: $('#importTpl').html(),
                        btn: ['<i class="dhicon dh-check"></i> 导入', '<i class="dhicon dh-remove"></i> 取消'],
                        shadeClose: true,
                        zIndex: 1000,
                        btn1: function (index, layero) {
                            var file = layero.find('#file');
                            if (!file[0]['value']) {
                                layer.msg("请选择文件！");
                                return false;
                            }
                            var imRes = importListExcel(file[0], importFields, 'productbasis');
                        }
                    });
                } else {
                    $.modal.alertWarning("后台未返回导入模板对象！");
                }
		    break;
			case 'zjimportBtn'://子件导入
			    if (importFieldsZJ) {
                    thStr = '<tr><th><div style="width:30px;">序号</div></th>';
                    $.each(importFieldsZJ, function (i, val) {
                        fieldWidth[val] = fieldWidth[val] ? fieldWidth[val] : 100;	//默认宽度100px
                        thStr += '<th><div style="width:' + fieldWidth[val] + 'px;">' + i + '</div></th>';
                    })
                    thStr += '</tr>';
                    layer.open({
                        type: 1,
                        area: ['400px', '230px'],
                        fix: false, 
                        offset: '10%',
                        maxmin: true,
                        shade: 0.3,
                        title: '导入',
                        content: $('#zjimportTpl').html(),
                        btn: ['<i class="dhicon dh-check"></i> 导入', '<i class="dhicon dh-remove"></i> 取消'],
                        shadeClose: true,
                        zIndex: 1000,
                        btn1: function (index, layero) {
                            var file = layero.find('#file');
                            if (!file[0]['value']) {
                                layer.msg("请选择文件！");
                                return false;
                            }
                            var imRes = zjimportListExcel(file[0], importFieldsZJ, 'productbasis');
                        }
                    });
                } else {
                    $.modal.alertWarning("后台未返回导入模板对象！");
                }
		    break;
			case 'tableFull'://表格展开
				$('.north .layui-form').hide();
				table.reload('dhtable',{
					defaultToolbar: [{title:'收缩',layEvent:'tableShrink',icon:'layui-icon-screen-restore'}],
					height: $(window).height()-$('.north').height()-60<300?'300':$(window).height()-( $('.north').height()+$('.south').height()+12)
				});
			break;
			case 'tableShrink'://表格收缩
				$('.north .layui-form').show();
				table.reload('dhtable',{
					defaultToolbar: [{title:'展开',layEvent:'tableFull',icon:'layui-icon-screen-full'}],
					height: $(window).height()-$('.north').height()-60<300?'300':$(window).height()-( $('.north').height()+$('.south').height()+12)
				});
			break;
	 	    case 'fieldSet':
 	    		filedSet(moduleTable);
          	break;
 	    };
 	});

	//子件导入数据
    function zjimportListExcel(obj, importFieldsZJ, mName) {
    	var wb;//读取完成的数据
    	var rABS = false; //是否将文件读取为二进制字符串
    	var iid;
    	if(!obj.files) {
    		return;
    	}
    	const IMPORTFILE_MAXSIZE = 1*2048;       //这里可以自定义控制导入文件大小
    	var suffix = obj.files[0].name.split(".").slice(-1);
    	if(suffix != 'xls' && suffix !='xlsx'){
    		layer.msg('导入的文件格式不正确!')
    		return
    	}
    	if(obj.files[0].size/1024 > IMPORTFILE_MAXSIZE){
    		layer.msg('导入的表格文件不能大于2M')
    		return
    	}
    	showloadings(true);
    	var f = obj.files[0];
    	var reader = new FileReader();
    	var reStr='';
    	reader.onload = function(e) {
    		var data = e.target.result;
    		if(rABS) {
    			wb = XLSX.read(btoa(fixdata(data)), {     //手动转化
    				type: 'base64'
    			});
    		} else {
    			wb = XLSX.read(data, {
    				type: 'binary'
    			});
    		}
    		var strForm=XLSX.utils.sheet_to_json(wb.Sheets[wb.SheetNames[0]]);
    		var excelData = [], tStr = trStr='';
    		hasNull = false;
    		for(var i=0; i<strForm.length; i++){
    			var trData = {},strFormTr = {};
    			$.each(strForm[i], function(si, sv){
    				strFormTr[si.replace("*", "")] = sv;
    			})
    			trStr += '<tr><td style="text-align: center;">' + Number(i+1) + '</td>';
    			$.each(importFieldsZJ,function(j,v){
    				tStr = strFormTr[j.replace("*", "")] ? strFormTr[j.replace("*", "")] : '';
    				if(mName != "product" && $.inArray(v,dateFiled) > -1)tStr = tStr ? forDate(tStr) : '';
    				if(!hasNull &&  j.includes('*') && tStr == ''){
    					hasNull = "<p>第<span style='color:red'>"+Number(i+1)+"</span>行必填字段【<span style='color:red'>"+j.replace("*", "")+"</span>】不允许为空！</p>请核对数据，重新导入。";//导入数据必填字段有空值
    				}
    				trStr += '<td tindex="' + i + '" tfield="' + v + '">' + tStr + '</td>';
    				trData[v] = tStr;
    			})
    			trStr += '</tr>';
    			trData['iid'] = Number(i+1);
    			excelData.push(trData);
    		}
    		if(hasNull)layer.alert(hasNull, {icon:7});
    		$("#itbody").html(thStr + trStr);
    		zjintable(excelData, mName);
    	};
    	if(rABS) {
    		reader.readAsArrayBuffer(f);
    	} else {
    		reader.readAsBinaryString(f);
    	}
    	return true;
    }
    /*弹出层（导入列表内容）
     * mName：product产品;customer客户;provider供应商;
     */
    function zjintable(listDataObj, mName){
    	var stepNameMsg;
    	layer.open({
    		type: 1,
    		area: ['800px', '500px'],
    		fix: false,
    		offset: '10%',
    		maxmin: true,
    		shade: 0.3,
    		title: '导入列表',
    		content: $('#iForm').html()?($('#iForm').html()+$('#iTable').html()):$('#iTable').html(),//产品信息扩展iForm
    		btn: ['<i class="dhicon dh-check"></i> 确定', '<i class="dhicon dh-remove"></i> 取消'],
    		shadeClose: true,
    		zIndex: 1001,
    		success: function(layero, index){
    			showloadings(false);
    			form.render();
    		},
    		btn1: function(index, layero){
    			switch(mName){//点击确定导入时的判断
    				case 'product':
    					var errorRow = [];
    					var filterBlankArr = ['gBrand','gID','gModel','gName','gSerial','gUnit'];
    					$.each(listDataObj,function(i,v){
    						if(v.gBrand == 'AB' && v.gID.indexOf('-') != -1)errorRow.push(i+1);
    						$.each(filterBlankArr,function(ii,vv){//【品牌、型号、规格、品名、系列、单位】去除前后空格回车
    							if(v[vv])v[vv] = v[vv].replace(/(^\s*)|(\s*$)/g, "").replace(/[\r\n]/g, "");
    						})
    					})
    					if(errorRow.length){
    						$.modal.msgError("【AB】品牌下的型号不能带“-”！<br>错误行：第"+errorRow.join(',')+"行！", modal_status.FAIL);
    						return false;
    					}
    				case 'producthistory':
    					var iFormData=layero.find('form').serializeFormToJson();
    					if(!iFormData.fSl){layer.msg("请选择税率！", {icon:7});return false;}
    					if(!iFormData.fType){layer.msg("请选择税额计算相关！", {icon:7});return false;}
    					break;
    				case 'customer':
    				case 'provider':
    					cID = $(".layui-layer-page .cid").val();
    					if(!cID){layer.msg("请选择所属公司！", {icon:7});return false;}
    
    					bUser = $(".layui-layer-page .bUser").val();
    					bDept = $(".layui-layer-page .bDept").val();
    					if(!bUser){layer.msg("请选择所属员工！", {icon:7});return false;}
    
    					stepName = $(".layui-layer-page [name='stepName']").val();
    					if(!stepName){layer.msg(stepNameMsg, {icon:7});return false;}
    					break;
    			}
    			if(hasNull){
    				layer.alert(hasNull, {icon:7});
    				return false;
    			}
    			showloadings(true);
    			var importObj = [],
    				inum = 0,
    				onetime = 1,
    				flag = 1,
    				oneImportNum = 2, 						//默认一次导入条数
    				allImportNum = listDataObj.length, 		//数据总量
    				importBl = 0,	//导入进度
    				times = 0;		//请求次数
    			if(mName == 'product')$.operate.post("/business/product/cleanproductimportpost"); 		//清除导入旧数据
    			if(mName == 'producthistory')$.operate.post("/business/producthistory/cleanproductimportpost"); 		//清除导入旧数据
    			if(mName == 'productbasis')$.operate.post("/business/productbasis/cleanproductimportpost"); 		//清除导入旧数据
    			element.progress('dhprogress', '0%');
    			setTimeout(function(){
    				if(allImportNum > 9 && allImportNum <= 100){
    					oneImportNum = 5;
    				}else if(allImportNum > 100 && allImportNum <= 500){
    					oneImportNum = 30;
    				}else if(allImportNum > 500 && allImportNum <= 1000){
    					oneImportNum = 50;
    				}else if(allImportNum > 1000){
    					oneImportNum = 100;
    				}
    				times = Math.ceil(allImportNum/oneImportNum);
    				zjeachImport(listDataObj, 0, oneImportNum, allImportNum, times, 1);return false;
    			}, 1000);
    		}
    	});
    }
    
    
    
     });
    //通过guid彻底删除
    function remove(guid,code){
    	if(guid){
    		$.operate.remove("该删除无法恢复，请确认？",prefix + "/delete/",{'productBasisItems':JSON.stringify([{'guid':guid,code}])},function(result){
    			if(result.code==0){
    		        setTimeout(function(){
    		            layer.closeAll();
    		            table.reload('dhtable');
    		        }, 1000);
    		    }
    		});
    	}else{
    		if(table.checkStatus('dhtable').data.length>0){
    			$.operate.remove("是否彻底删除该"+table.checkStatus('dhtable').data.length+"条产品？",prefix + "/delete/",{'productBasisItems':JSON.stringify(table.checkStatus('dhtable').data, null, 2)},function(result){
    				if(result.code==0){
    			        setTimeout(function(){
    			            layer.closeAll();
    			            table.reload('dhtable');
    			        }, 1000);
    			    }
    			});
    		}else{
    			layer.msg("无勾选数据！");
    		};
    	}
    }

    //启停
    function updateState(guid,type){
    	var isUsable = (type === 0 ? "启用":"停止");
		$.operate.remove("是否"+isUsable+"，请确认？",prefix + "/updateState/",{'infoItem':JSON.stringify({'guid':guid,isUsable})},function(result){
			if(result.code==0){
				setTimeout(function(){
					layer.closeAll();
					table.reload('dhtable');
				}, 1000);
			}
		});
    }

//通过guid彻底删除
function zjremove(guid,code){
	if(guid){
		$.operate.remove("该删除无法恢复，请确认？",prefix + "/deletezj",{'productBasisComponentItems':JSON.stringify([{'guid':guid,code}])},function(result){
			if(result.code==0){
		        setTimeout(function(){
		            layer.closeAll();
		            table.reload('dhtable');
		        }, 1000);
		    }
		});
	}else{
		if(table.checkStatus('dhtable').data.length>0){
			$.operate.remove("是否彻底删除该"+table.checkStatus('dhtable').data.length+"条产品？",prefix + "/deletezj",{'productBasisComponentItems':JSON.stringify(table.checkStatus('dhtable').data, null, 2)},function(result){
				if(result.code==0){
			        setTimeout(function(){
			            layer.closeAll();
			            table.reload('dhtable');
			        }, 1000);
			    }
			});
		}else{
			layer.msg("无勾选数据！");
		};
	}
}

/*批量请求导入数据
 *tobj：导入数据对象
 *startNum：从第几条开始导入
 *oneImportNum：每次导入条数
 *allImportNum：总数据量
 *times：导入次数times
 */
 function zjeachImport(tobj,startNum, oneImportNum, allImportNum, times, timeNum){
	var importObj = [];
	for(var i = 0; i < allImportNum; i++){
		importObj.push(tobj[i]);
	}
	$.ajaxSettings.async = false;
	$.post(prefix+"/addzjpost", {'productBasisComponentItems':JSON.stringify(importObj)}, function(res) {
		layer.msg(res.msg)
		if(res.code==0){
            setTimeout(()=>{
				location.reload();
			},1000)
		}
    });
}

/*批量请求导入数据
 *tobj：导入数据对象
 *startNum：从第几条开始导入
 *oneImportNum：每次导入条数
 *allImportNum：总数据量
 *times：导入次数times
 */
 function eachImport(tobj,startNum, oneImportNum, allImportNum, times, timeNum){
	var importObj = [], inum = startNum, importBl='0%';
	for(var i = startNum; i < startNum + oneImportNum; i++){
		if(i >= allImportNum)break;
		inum = i + 1 ;
		tobj[i]['vCpFl'] = vCpFl;
		importObj.push(tobj[i]);
	}
	$.ajaxSettings.async = false;
	$.post("/business/productbasis/importpost", {'productBasisItems':JSON.stringify(importObj, null, 2),'fSl':$('#fSl').val(),'fType':$("[name='fType']:checked").val()}, function(result) {
		importBl = (inum/allImportNum)*100;
		console.log('导入比:'+importBl.toFixed(2)+ '%');
		console.log('数量:'+inum);
		console.log('总次数:'+times);
		console.log('当前次数:'+timeNum);
		importObj = [];
		timeNum += 1;
    },"json");
	setTimeout(function(){
		if(timeNum <= times){
			eachImport(tobj, startNum + oneImportNum, oneImportNum, allImportNum, times, timeNum);	
		}else{
			element.progress('dhprogress', importBl.toFixed(2)+ '%');
			showloadings(false);
			$.post("/business/productbasis/importtoprocuctpost", {'records':allImportNum}, function(res){
				closeProcess(res, 'product');
			},"json")
		}
		element.progress('dhprogress', importBl.toFixed(2)+ '%');
	},500);
}

</script>
</body>
</html>